package com.akhan.jplearn.service.impl;

import cn.hutool.core.util.StrUtil;
import com.akhan.jplearn.mapper.JPWordMapper;
import com.akhan.jplearn.service.SearchService;

import java.util.Scanner;

/**
 * 查找服务实现
 *
 * @author YuKang
 * @date 2021/6/25 0:13
 */
public class SearchServiceImpl extends BaseServiceImpl implements SearchService {


    @Override
    public String search(String in) {
        String ret = null;

        int idx = JPWordMapper.indexOf(in);
        if (idx == -1) {
            return "没有找到对应的数据";
        }
        if (in.matches("^[a-zA-Z]+")) {
            ret = StrUtil.format("平假名：【{}】， 片假名：【{}】", JPWordMapper.getHiragana(idx), JPWordMapper.getKatakana(idx));
        } else {
            ret = StrUtil.format("五十音: 【{}】", JPWordMapper.getGojyuuon(idx));
        }

        return ret;
    }


    @Override
    String core(String in) {
        return search(in);
    }

    @Override
    String getName() {
        return "五十音速查";
    }
}
